﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PersonaLibrary.ViewModel.EmployeeViewModel
{
    public class AllEmployeeViewModel : FilteredCollectionViewModel<DataModel.EmployeeEntity>
    {
        private RelayCommand editEmployeeCommand;

        public RelayCommand EditEmployeeCommand
        {
            get
            {
                if (editEmployeeCommand == null)
                    editEmployeeCommand = new RelayCommand(param => EditEmployee(param), param => param is Data.Employee);
                return editEmployeeCommand;
            }
        }

        public AllEmployeeViewModel()
            : base()
        {
            base.FilteredPropertyName = "Surname";
            base.FilteredPropertyValue = " ";
            base.OrderPropertyName = "Surname";
            base.ItemFilterSource = " АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ".ToList();
            base.SetItemTemplate(new Uri("/../View/FilterItemTemplate.xaml", UriKind.Relative), "EmploeeDetail");
        }

        public void EditEmployee(object arg)
        {
            
        }

        public override Func<DataModel.EmployeeEntity, bool> Filter
        {
            get
            {
                if (!string.IsNullOrEmpty(FilteredPropertyName) && FilteredPropertyValue != null)
                {
                    return x => x.GetType().GetProperty(FilteredPropertyName).GetValue(x, null).ToString().StartsWith(FilteredPropertyValue.ToString());
                }
                else return null;
            }
        }
    }
}
